﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileDB
{
    public class Helper
    {
        public static bool MatchPassword(string password, string expectedpasswordstr)
        {
            if (GeneratePasswordStr(password) == expectedpasswordstr)
                return true;
            else
                return false;
        }


        public static string GeneratePasswordStr(string p)
        {
            return GetMD5Hash(p);
        }

        public static string GetMD5Hash(string input)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }

    }
}
